package com.dtw.ditouwang.ui.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.RecordBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RecordActivity extends BaseActivity {
    List<RecordBean.DataBean> recordBeanList = new ArrayList<>();
    RecordAdapter recordAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        enableBack();
        setTitle("运动记录");
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recordAdapter = new RecordAdapter(recordBeanList);
        recyclerView.setAdapter(recordAdapter);

        webApi.getRecord(UserRepository.getInstance().getUserID()).enqueue(new Callback<RecordBean>() {
            @Override
            public void onResponse(Call<RecordBean> call, Response<RecordBean> response) {
                if (response.body().isResult()) {
                    recordBeanList.clear();
                    recordBeanList.addAll(response.body().getData());
                    recordAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<RecordBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
